﻿using AiBLSmartEdu.Module.Auth.API.DTOs;
using AiBLSmartEdu.Module.Auth.API.Services;
using FrameworkCore.Controllers;
using FrameworkCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AiBLSmartEdu.Module.Auth.API.Controllers;

public class AuthController : BaseModuleController
{
    private readonly AuthServices _authServices;

    public AuthController(AuthServices authServices)
    {
        _authServices = authServices;
    }

    /// <summary>
    /// 密码登录
    /// </summary>
    /// <param name="input">输入模型</param>
    /// <returns></returns>
    [HttpPost("Login")]
    [AllowAnonymous]
    public async Task<Result<LoginOutputModel>> LoginAsync(LoginInputModel input)
    {
        return await Result<LoginOutputModel>.SucceedAsync(await _authServices.LoginAsync(input));
    }

    /// <summary>
    /// 刷新令牌
    /// </summary>
    /// <param name="input">输入模型</param>
    /// <returns></returns>
    [HttpPost("refresh-token")]
    [AllowAnonymous]
    public async Task<Result<LoginOutputModel>> RefreshTokenAsync(RefreshTokenInputModel input)
    {
        return await Result<LoginOutputModel>.SucceedAsync(await _authServices.RefreshTokenAsync(input));
    }

    /// <summary>
    /// 用户注册
    /// </summary>
    /// <param name="input">输入模型</param>
    /// <returns></returns>
    [HttpPost("Register")]
    [AllowAnonymous]
    public async Task<Result<bool>> RegisterAsync(RegisterInputModel input)
    {
        return await Result<bool>.SucceedAsync(await _authServices.RegisterAsync(input));
    }
}
